﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using static ServerGame.Service.Dispatcher;
using ServerBase.Client;
using System;
using ServerPublic.Data;
using ServerGame.GameObject;
using static UtilPublic.Serialization.Jsh;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerGame.Data;

namespace ServerGame.Manager
{
    /// <summary>
    /// 管理 聊天
    /// </summary>
    public static class ChatMgr
    {
    }
    public partial class DispatcherMsg
    {

        [ApiDpPro((short)EProtocolId.C2G_CHAT_SEND, "聊天信息发送")]
        public short OnChatSend()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnChatSend();

            if (Req.Text.Length > 400)
            {
                Rsp.Result = EProtocolResult.文本太长; return Send(Rsp);
            }
            var dtNow = DateTime.Now;
            if (dtNow < player.DtLastChat.AddSeconds(1))
            {
                Rsp.MessageFail("聊天发送太频繁！"); return Send(Rsp);
            }
            player.DtLastChat = dtNow;

            var msg = new G2C_Chat_Receive();
            msg.Msg = new CLS_ChatMsg()
            {
                ChatType = Req.ChatType,
                Text = Req.Text,
                Sender = player.Name,
            };

            Send(Rsp);

            switch (Req.ChatType)
            {
                case EChatType.房间:
                    break;
                case EChatType.门派:
                    break;
                case EChatType.帮会:
                    break;
                case EChatType.私聊:
                    break;
                default:
                    Dispatcher.Boardcast(msg);
                    break;
            }
            return 0;
        }

    }
}
